<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0px;
            padding: 0px;
            box-sizing: border-box;
        }
        .nav {
            width: 800px;
            height: 100px;
            margin: 0 auto;
            display: flex;
            align-items: center;
        }
        .nav input {
            width: 600px;
            height: 60px;
            border-radius: 5px;
        }
        .nav button {
            width: 200px;
            height: 60px;
            background-color: orange;
            color: white;
            font-size: 20px;
            border: orange;
            border-radius: 5px;
        }
        .nav button:active {
            background-color: grey;
        }
        .container {
            width: 800px;
            display: flex;
            margin: 0px auto;
        }
        h3 {
            background-color: gray;
            color: white;
            text-align: center;
            width: 400px;
            height: 60px;
            padding-top: 15px;
        }
        .todo,
        .done {
            width: 50%;
            height: 100%;
        }
        .row {
            width: 400px;
            display: flex;
            align-items: center;
        }
        span {
            width: 200px;
            font-size: 20px;
            margin-left: 5px;
        }
        .row button {
            width: 90px;
            height: 40px;
            font-size: 20px;
            margin-top: 10px;
        }
        /* s */
    </style>
</head>
<body>
    <div class="nav">
        <input type="text"><button onclick="newJob()">新建任务</button>
    </div>
    <div class="container">
        <div class="todo">
            <h3>未完成</h3>
            <div class="row">
                <input type="checkbox" name="" id="">
                <span>吃饭</span><button>删除</button>
            </div>
            <div class="row">
                <input type="checkbox" name="" id="">
                <span>吃饭</span><button>删除</button>
            </div>
        </div>
        <div class="done">
            <h3>已完成</h3>
        </div>
    </div>
</body>
<script>
    function newJob() {
        // 获取到input输入框按钮
        let input = document.querySelector('.nav input')
        // 获取到输入的信息
        let input_info = input.value
        if(input_info == '') {
            return
        }
        console.log(input_info)
        // 获取到todo这个div
        let todo = document.querySelector('.todo')
        // 创建一个div
        let div = document.createElement('div')
        // 创建一个checkbox
        let checkbox = document.createElement('input')
        checkbox.type = 'checkbox'
        // 创建一个span（文本内容是刚才输入的信息对应的文本）
        let span = document.createElement('span')
        span.innerHTML = input_info
        console.log(checkbox)
        console.log(span)
        // 创建一个删除button
        let button = document.createElement('button')
        button.innerHTML = "删除"
        div.appendChild(checkbox)
        div.appendChild(span)
        div.appendChild(button)
        console.log(div)
        // 更新样式
        div.className = 'row'
        // // 将div插入到todo这个div中
        todo.appendChild(div)

        let delete_buttons = document.querySelectorAll('.row button')
        console.log(delete_buttons)
        for(i = 0; i < delete_buttons.length; i++) {
            delete_buttons[i].onclick = function() {
                let parent = this.parentNode;
                console.log(parent)
                let grand_parent = parent.parentNode
                console.log(grand_parent)
                grand_parent.removeChild(parent)

            }
        }
        let checkbox_buttons = document.querySelectorAll('.row input')
        // 给每一个复选框绑定点击事件
        for(i = 0; i < checkbox_buttons.length; i++) {
            checkbox_buttons[i].onclick = function() {
                // 将节点插入到对应的div中
                // row代表的插入的节点
                let row = this.parentNode;
                // target代表的是将row插入到那个div中
                // 如果复选框已经被选中，那么target就是已完成对应的这个div
                // 否则target就是未完成对应的div
                let target;
                console.log(this.checked)
                if(this.checked) {
                    target = document.querySelector('.done') 
                } else {
                    target = document.querySelector('.todo')
                }
                target.appendChild(row)
            }
        }

}

    
</script>
</html>